import {Injectable} from '@angular/core';
import {WindowService} from './window.service';
import {ConfirmContentComponent} from '../../page/system/confirm/confirm.content.component';
import {ObjectUtil} from '../../shared/utils/object-util';
import {NzMessageService} from "ng-zorro-antd/message";
import {NzNotificationService} from "ng-zorro-antd/notification";

@Injectable()
export class MessageService {

  constructor(private messageService: NzMessageService, private notification: NzNotificationService, private windowService: WindowService) {
  }

  info(message) {
    this.messageService.info(message);
  }

  success(message) {
    this.messageService.success(message);
  }

  error(message) {
    this.messageService.error(message);
  }

  warning(message) {
    this.messageService.warning(message);
  }

  notifyError(msg, ...title) {
    this.notification.create('error', ObjectUtil.isNotEmpty(title) ? title[0] : 'error', msg, {nzDuration: 6000});
  }

  notifySuccess(msg, ...title) {
    this.notification.create('success', ObjectUtil.isNotEmpty(title) ? title[0] : 'success', msg);
  }

  notifyInfo(msg, ...title) {
    this.notification.create('info', ObjectUtil.isNotEmpty(title) ? title[0] : 'info', msg);
  }

  openAlert(msg) {
    this.windowService.openWindow({
      component: ConfirmContentComponent,
      title: '提示',
      width: 300,
      showCloseBtn: false,
      buttonStyle: {'text-align': 'center'},
      data: {message: msg},
    });
  }

  openConfirm(msg, okFun) {
    this.windowService.openWindow({
      component: ConfirmContentComponent,
      title: '提示',
      width: 300,
      buttonStyle: {'text-align': 'center'},
      data: {message: msg},
      afterOk: okFun
    });
  }


}
